<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/css.css">
<script src="js/flexible.js"></script>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/public.js"></script>
<script type="text/javascript" src="js/layer.js"></script>
<script src="js/common.js"></script>
<script type="text/javascript">
  isLogin();
</script>
<style>
#radio{
    -webkit-appearance:radio !important;
    appearance:radio !important;
}</style>
</head>
<body class="jui_bg_zhuse">
<!-- 头部 -->
<div class="jui_top_bar">
     <a class="jui_top_left" href="javascript:history.back(-1)"><img src="icons/back_111.png"></a>
     <div class="jui_top_middle">添加收款方式</div>
</div>
<!-- 头部end -->
<div class="jui_main">
<div class="jui_h16"></div>
<!-- 主体 -->
<form action="">
<div class="jui_pad_l16 jui_pad_r16">
      <div class="jui_public_list jui_bor_rad_5 skfs_inpubar">
           <div class="jui_fc_lightzs jui_pad_r12">收款渠道</div>
          <div class="jui_fc_lightzs">微信或支付宝</div>
           <!--<select class="jui_flex1 jui_fc_lightzs" id="p_type">
                 <option value="1">微信</option>
                 <option value="2">支付宝</option>
           </select>
           <img class="jui_arrow_rimg" src="icons/jt_right.png">-->
      </div>
      <div class="jui_public_list jui_bor_rad_5 skfs_inpubar">
           <div class="jui_fc_lightzs jui_pad_r12">收款账号</div>
           <input class="jui_flex1" type="text" value="" placeholder="请输入微信或支付宝收款账号" id="p_num">
      </div>
      <div class="jui_fc_lightzs jui_pad_b16">收款二维码</div>
      <div class="jui_bg_ztqian jui_flex_col_center jui_pad_20 jui_bor_rad_5">
           <div id="shoukuan">
                <img id="imghead" border="0" src="icons/add_img2.png" onerror = "this.src = 'icons/add_img.png'"  onclick="return false;">
           </div>
           <input type="file" onChange="previewImage(this)" style="display:none;" id="previewImg" />
           <div class="jui_h12"></div>
           <p class="jui_fc_lightzs">点击上传收款码</p>
      </div>
      <div class="jui_h16"></div>
      <div class="jui_public_list jui_flex_justify_between jui_bor_rad_5 skfs_inpubar jui_mar_bnone">
           <div class="jui_flex_row_center">
           	<p class="jui_fc_lightzs jui_flex_no jui_pad_r12">验证码</p>
           <input style="width:3rem;" type="tel" placeholder="请输入验证码" id="pay_code">
           </div>
           <input id="jui_form_yzm" class="jui_fc_lan" type="button" value="获取验证码">
      </div>
    <!-- <div class="jui_public_list jui_flex_justify_between jui_bor_rad_5 skfs_inpubar jui_mar_bnone" style="margin-top:2vw;align-items:center;">
      <div style="font-size: .37333rem;color:#999;">是否设置为默认收款方式: </div>
      <label for="" style="display:flex;align-items:center;"><input type="radio" id="radio" style="width:.5rem;height:.5rem;-webkit-appearance:normal;appearance:normal;margin-right:.2rem;" value="1" /><span style="line-height:.6rem;">是</span></label>
    </div>-->
</div>
<div class="jui_public_btn"><input type="button" value="提交审核" id="btn"></div>
</form>
<!-- 主体end -->
</body>
<script>
//倒计时  不需要jquery库
var regcode = true;
var p_phone = window.location.search.split("=")[1];
var p_id;
var input = document.createElement('input');
       input.type = 'file';
       input.accept = 'image/*';
var reqxq = {
  uid: localStorage.getItem('h_uid'),
  token: localStorage.getItem('h_token'),
}
	function settime(num){
		var yzm_input=document.getElementById("jui_form_yzm"); //如果用getElementsByClassName获取类，获取的为数组，下面的yzm_input要改为yzm_input[0]
		var num;
		if( num==0 ){
      regcode = true;
			yzm_input.value="重新发送";
			yzm_input.removeAttribute("disabled");
			yzm_input.setAttribute("class","jui_fc_lan")
			return false; //直到倒计时0时停止执行函数
			}else{
        regcode = false;
				yzm_input.setAttribute("disabled","disabled");
				yzm_input.setAttribute("class","jui_fc_lan")
				yzm_input.value=num+"s后重发";
				num--;
				}
		 //setTimeout(function(){settime(num)},1000);
		 setTimeout("settime("+num+")", 1000); //num为变量，所以要用“+”链接
	}
  $(function() {
    var p_img = null;
    //给
    $.ajax({type:'post', url: baseURL + '/index.php?m=user&c=pay_info', data: reqxq, success: function(data) {
      data = JSON.parse(data);
      if(data.code != 200) {
        layer.open({
          time:1 ,
          skin: 'msg',
          content: data.msg
        })
        setTimeout(()=>{
          window.history.back(-1);
        }, 1000)
        return;
      }
      p_id = data.data.p_id || 0;
      $("#imghead").attr('src', data.data.p_img);
      data.data.p_img = data.data.p_img || "";
      p_img = data.data.p_img.replace(/^(http|https)[\w\.\:\/]*(?=\/static\/)/, '.');
      $("#p_num").val(data.data.p_num);
    }})
    //
    $("#jui_form_yzm").on('click', function() {
      if(!regcode){
        return;
      }
      $.ajax({type: 'post', url: baseURL + '/index.php?m=index&c=setpay_smscode', data:{m_phone: p_phone}, success: function(data) {
        data = JSON.parse(data);
        if(data.code == 200) {
          settime(60);
          layer.open({
            content: data.msg,
            time: 1,
            skin: 'msg'
          })
        }
      }})
    })
    $("#btn").on('click', function() {
      if(!$("#p_num").val()) {
        layer.open({
          content: '收款账号不能为空',
          skin: 'msg',
          time: 1
        })
        return ;
      }
      if(!p_img) {
        layer.open({
          content: '收款码不能为空',
          skin: 'msg',
          time: 1
        })
        return ;
      }
      $.ajax({type: 'post', url: baseURL + '/index.php?m=user&c=is_setup', data: reqxq, success: function(data) {
        data = JSON.parse(data);
        if(data.code != 200) {
          layer.open({content: data.msg, time: 1, skin: 'msg'})
          setTimeout(()=>{
            window.history.back(-1)
          }, 1000)
          return;
        }
        if(data.is_rz == 1) {
          var req = {
            uid: localStorage.getItem('h_uid'),
            token: localStorage.getItem('h_token'),
            p_type: 1,
            p_id,
            p_status: 1,
            p_num: $("#p_num").val(),
            p_img,
            p_phone,
            pay_code: $("#pay_code").val(),
          }
          var formdata = new FormData();
          for(let attr in req) {
            formdata.append(attr, req[attr])
          }
          $.ajax({type: 'post', url: baseURL + '/index.php?m=user&c=pay_save', contentType: false, data: formdata, processData: false, success: function(data) {
            data = JSON.parse(data);
            if(data.code == 200) {
              setTimeout(()=> {
                window.location.href = 'center.html';
              }, 1000)
              layer.open({
                content: '添加成功',
                skin: 'msg',
                time: 1
              })
            }else {
              layer.open({
                content: data.msg,
                skin: 'msg',
                time: 1
              })
            }
          }})
        } else {
          layer.open({content: '请先完成实名认证', time: 1, skin: 'msg'});
          setTimeout(()=>{
            window.history.back(-1);
          }, 1000)
        }
      }})
    })
    $("#shoukuan").on('click', function() {
       var reader = new FileReader();
       input.onchange = function() {
         var file = this.files[0];
         console.log(file.name);
         if(!/(jpg|png|jpeg)$/.test(file.name)) {
           layer.open({
             content: '仅支持png,jpg格式图片',
             time: 1,
             skin: 'msg'
           })
           return;
         }
         reader.readAsDataURL(file);
         reader.onload = function() {
           $("#imghead").attr('src', this.result);
           p_img = file;
         }
         input = document.createElement('input');
         input.type = 'file';
         input.accept = 'image/*';
       }
       input.click();
   })
  })

</script>
</html>
